(function() {
	var $editBtn, $pageCSS, $statusSor, $subjInput, Deep, areaOptions, ctrlFlag, hoverFlag, markCSS, rt_link, serialNum, statusOptions, unmarkCSS;

	$statusSor = $('<select style="display: none">\n\n</select>');

	statusOptions = $('<option value="open"> open </option>\n<option value="stall"> stalled </option>\n<option value="resolve"> resolved </option>\n<option value="kill" disabled=\'disabled\'> dead </option>');

	areaOptions = $('<option> None </option>\n<option>Declined</option>\n<option>Inquiries</option>\n<option>Interview Requested</option>\n<option>Placed - Admin</option>\n<option>Placed - CC</option>\n<option>Placed - PA</option>\n<option>Placed - US/UT</option>\n<option>Staff Requests</option>');

	$editBtn = $('<div id=\'edit\' style=\'position: absolute; display: table; text-align: right; color: RED; margin-top: -2px;\'>\n	<font style=\'font-size: 15px;\'>\n		[Edit]\n	</font>\n</div>');

	$subjInput = $('<p style="display: none" id="genTextWrap">\n	<input type="text" id="genTextArea"/>\n	<br />\n	<input type="submit" class="saveBtn" value="Save" />\n	<input type="submit" class="cancelBtn" value="Cancel">\n</p>');

	$pageCSS = '\
		<style type="text/css">\
		\
		.dropDownCell, .inputTypeCell{\
			height: 40px;\
		}\
		\
		.dropDownCell, #edit > font{\
			cursor: hand;\
		}\
		\
		#genTextArea{\
			width: 100%;\
			border: solid 1px gray;\
		}\
		\
		#msgDisplay{\
			height: 30px;\
			position: absolute;\
			text-align: center;\
		}\
		\
		#msgDisplay > font{\
			padding-left: 10px;\
			padding-right: 10px;\
			background-color: #A2CD5A !important;\
			font-size: 15px;\
			color: #000000;\
		}\
		\
		</style>';

	markCSS = {
		'border-color': 'transparent',
		'border-style': 'solid'
	};

	unmarkCSS = {
		'border-color': 'none',
		'border-style': 'none'
	};

	Deep = true;

	serialNum = /serial_num=(\d+)/;

	rt_link = "/rt/webrt.cgi";

	ctrlFlag = false;

	hoverFlag = false;

	jQuery(function($) {

		$(document).on('scroll ready', function() {
			$('#msgDisplay').css({
				'top': window.pageYOffset
			});
			$('#msgDisplay').css({
				'width': window.innerWidth
			});
		});
		
		$('html').on('click', 'INPUT[value="Login"]', function() {

			var $strLogin;
			$strLogin = 'username=' + $('INPUT[name="username"]').attr('value') + 
						'&password=' + $('INPUT[name="password"]').attr('value');
			$.get(rt_link, $strLogin, function(data, textStatus, jqXHR) {
				$('html').html(data);
			});
			return false;
		});

		$.get(rt_link, function(data, textStatus, jqXHR) {

		$('html').html(data);
			
		$('font[size="-1"] > table').before("<div id='msgDisplay' style='width: " + window.innerWidth + ";'>		<font style='font-size: 14px; display: none;'></font>		</div>");
		$('#msgDisplay').before('<div id="hiddenWrapper" style="display: none !important;"></div>');
		$('#hiddenWrapper').before($pageCSS);
		
		$('html').on('click', 'a', function() {
        	var href;
        	href = $(this).prop('href');
        	$.get(href, function(data) {
          		return $('html').html(data);
        	});
        	return false;
		});
		$('html').on('click', 'INPUT[value="Update Queue Filters"]', function() {
        	var $qFilters;
        	$qFilters = $('body >form').serialize();
        	$.get(rt_link, $qFilters, function(data, textStatus, jqXHR) {
				return $('html').html(data);
        	});
        	return false;
		});
		$('html').on('click', 'INPUT[value="Create request in queue"]', function() {
        	var qid;
        	qid = $('form :input[name="queue_id"]').val();
        	$.get(rt_link, "queue_id=" + qid + "&display=Create_Step2", function(data, textStatus, jqXHR) {
          		return $('html').html(data);
        	});
        	return false;
		});
		$('html').on('click', 'INPUT[value="Create request"]', function() {
        	var $newReq;
        	$newReq = $('body >center >form').serialize();
        	$.get(rt_link, $newReq, function(data, textStatus, jqXHR) {
				return $('html').html(data);
			});
        	return false;
		});
		$('html').on('click', 'INPUT[value="Display request #"]', function() {
        	var sid;
        	sid = $('form :input[name="serial_num"]').val();
        	$.get(rt_link, "display=History&serial_num=" + sid, function(data, textStatus, jqXHR) {
				return $('html').html(data);
        	});
        	return false;
		});

		$('font >table >tbody >tr').rtTickets();

    });
  });

}).call(this);
